function [ coeff ] = fitPlane(points)
%FITPLANE Finds the best fit plane for a 3D list of points
%   Detailed explanation goes here

[rows cols] = size(points);

A=[points(:,1),points(:,2),points(:,3),ones(rows,1)];
[U,S,V]=svd(A);
ss=diag(S);
i=find(ss==min(ss)); % find position of minimal singular value
coeff=V(:,min(i)); % this may be multiple
coeff=coeff/norm(coeff(1:3),2);

end

